<?php

class Ucenik extends BaseUcenik
{
    public function __toString()
    {
        return $this->getPrezime().' '.$this->getIme();
    }

    public function joinIme()
    {
        return $this->getColumn('Prezime').' '.$this->getColumn('Ime');
    }

    public function getString()
    {
        return (string)$this;
    }

    public function getPrezime()
    {
        return $this->getProfil()->getPrezime();
    }

    public function getIme()
    {
        return $this->getProfil()->getIme();
    }

    public function getUsername()
    {
        return $this->getProfil()->getUsername();
    }

    public function getPassword()
    {
        return $this->getProfil()->getPassword();
    }

    public function getPlainPassword()
    {
        return $this->getProfil()->getPlainPassword();
    }

    public function getTelefon()
    {
        return $this->getProfil()->getTelefon();
    }

    public function getMobilni()
    {
        return $this->getProfil()->getMobilni();
    }

    public function getEmail()
    {
        return $this->getProfil()->getEmail();
    }

    public function getPol()
    {
        return $this->getProfil()->getPol();
    }

    public function getLastActiv()
    {
        return date('d.n.Y. / G-i', $this->getProfil()->getLastActiv());
    }

    public function delete(PropelPDO $con = null)
    {
        // Brisi i roditelja ako nema vise dece
        if(DbFinder::from('Ucenik')->where('RoditeljId', $this->getRoditeljId())->count() === 1)
        {
          RoditeljPeer::retrieveByPK($this->getRoditeljId())->delete();
          ProfilPeer::retrieveByPK($this->getId())->delete();
        }

        else ProfilPeer::retrieveByPK($this->getId())->delete();
        return 1;
    }

    public function getSrSlovo()
    {
        $roditelj = $this->getRoditelj();
        if($roditelj->getIme() != '')
          return mb_substr($roditelj->getIme(), 0, 1, 'UTF-8');
        else if($roditelj->getImeMajka() != '')
          return mb_substr($roditelj->getImeMajka(), 0, 1, 'UTF-8');
        else if($roditelj->getImeStaratelj() != '')
          return mb_substr($roditelj->getImeStaratelj(), 0, 1, 'UTF-8');
    }

    public function getUcenikSrSlovo()
    {
        return $this->getPrezime().' '.$this->getSrSlovo().' '.$this->getIme();
    }

}